/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { MetricService } from '../../../../src/base/metrics/metric-service';
import { MetricType } from '../../../../src/base/metrics/metric';

describe('metrics', () => {
  test.concurrent('metrics', () => {
    const service = MetricService.getInstance();
    const metric = MetricService.getInstance().newMetric('overallTime',
      'default@PreBuild', 'entry')
      .withType(MetricType.BUILD_LINE);
    setTimeout(() => {
      metric.close();
      expect(metric.getStatus()).toEqual('closed');
      expect(service.queryReport().getValue().length).toEqual(1);
      expect(service.queryReport().getValue()[0]).toEqual(metric);
      service.clear();
      expect(service.queryReport().getValue().length).toEqual(0);
    }, 1000);
    expect(metric.getName()).toEqual('overallTime');
    expect(metric.getTaskName()).toEqual('default@PreBuild');
    expect(metric.getTaskPath()).toEqual('entry');
    expect(metric.getType()).toEqual('build_line');
    expect(metric.getWorkerId()).toEqual(-1);
  });
});
